#include <iostream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>

const int size = 20;

struct count {
	count(int kk=0):k(kk) {}
	int k;
	int operator()() {
		return k++;
	}
};

void print_perm(const std::vector<int>& v) {
		std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout, " "));
		std::cout<<std::endl;
}

void permutation(std::vector<int> v,int k) {
	if (k==size) {
		print_perm(v);
		return;
	}
	
	for (int i=k; i<size;i++) {
		std::swap(v[i],v[k]);
		permutation(v,k+1);
		std::swap(v[i],v[k]);
	}
}

int main(int argc, char **argv) {
	//int beg = atoi(argv[1]);
	std::vector<int> v(size);
	std::generate(v.begin(),v.end(),count());
//	std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout," "));
	permutation(v,0);
}
